[Console] Document #[Argument] and #[Option] attributes for invokable commands#21652
Conversation
| { | ||
| public function __invoke( | ||
| #[Option(shortcut: 'f')] bool $foo = false, | ||
| #[Option(shortcut: 'b')] string $bar = '', |
There was a problem hiding this comment.
The value of the
baroption (and itsbshortcut respectively) is required.
So default to empty string must be removed ? (en reorder args)
This sentence if not true with options attributes write ?
There was a problem hiding this comment.
it's true, and it refers to the moment when the option is used; at that point, we're forced to set a value for that option.
in other words, having a default value (which is required for options) means it's the value used when the option is not passed on the command line. When the option is passed, it must include a value, e.i. --opt=1, passing just --opt is forbidden under this definition
9a523f3 to
0a2c166
Compare
javiereguiluz
left a comment
There was a problem hiding this comment.
Great contribution! Thanks Yonel.
I only have a minor question after reviewing the contents.
|
|
||
| ``name`` | ||
| The name of the argument (by default, the parameter name converted to ``kebab-case``). | ||
| For example: ``#[Argument(name: 'user-name')]``. |
There was a problem hiding this comment.
Where is this name used? Because user-name would be no valid PHP variable name, so I'm not sure where this value is used in practice. Thanks.
There was a problem hiding this comment.
These names show up in the help output, but also it's still possible to get an argument via $input->getArgument('user-name')
There was a problem hiding this comment.
We can use this name when we want it to differ from the property/parameter name.
|
|
||
| ``name`` | ||
| The name of the option (by default, the parameter name converted to ``kebab-case``). | ||
| For example: ``#[Option(name: 'max-retries')]``. |
There was a problem hiding this comment.
Same question here as in the arguments section.
There was a problem hiding this comment.
This one is more visible, since the user will use this name to pass the option: --max-reties=10
|
This is now merged! Thanks Yonel for such a nice contribution. Also, while merging I expanded some explanations a bit based on your feedback to my comments. See 3f81441 Thanks! |
Part of #20553.
I kept both approaches for now so that later we can extract the classic approach into a new section as part of #21168.